import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout/index.vue'
import Homes from '../views/Home/index.vue'
Vue.use(VueRouter)

const home = () => import("../views/Home.vue")    //懒加载
const login = () => import("../views/login.vue")
const register = () => import("../views/register.vue")
// 一级路由
const Goods=()=> import("../views/Goods/Goods.vue")
const Parms=()=> import("../views/Params/Params.vue")
const Advert=()=> import("../views/Advert/Advert.vue")
const Order=()=> import("../views/Order/index.vue")
// 二级路由
const OrderList=()=> import("../views/Order/OrderList/index.vue")
const OrderBack=()=> import("../views/Order/OrderBack/index.vue")
const routes = [
  {
    path: '',
    redirect: '/login'   //重定向
  },
  {
    path:'/Layout',
    component:Layout,
    children:[
      {
        path:'/Layout/Homes',
        name:'Homes',
        component:Homes
      },
      {
        path:'/Layout/goods',
        name:'Goods',
        component:Goods
      },
      {
        path:'/Layout/parms',
        name:'Parms',
        component:Parms
      },
      {
        path:'/Layout/advert',
        name:'Advert',
        component:Advert
      },
      {
        path:'/Layout/order',
        name:'Order',
        component:Order,
        // 重定向
        redirect:'/Layout/order/order-list',
        children:[
          {
            path:'order-list',
            component:OrderList
          },
          {
            path:'order-back',
            component:OrderBack
          }
        ]
      }
    ]
  },
  {
    path: '/home',
    name: 'home',
    component: home
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/register',
    name: 'register',
    component: register
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//使用push的方法
const RouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return RouterPush.call(this, to).catch(err => err)
}

//使用replace的方法
const RouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (to) {
  return RouterReplace.call(this, to).catch(err => err)
}


export default router
